<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/28
 * Time: 12:26
 */

/**
 * Class Involved_CollectionModel
 */

class Involved_CollectionModel extends BaseModel{

    protected $table = 'collection';

    /**
     * 获取收藏列表
     * @param $user_id
     * @return mixed
     * @author alice
     * @date 2016-2-16
     */
    public function GetCollectionList($page,$user_id)
    {
        $offset = ($page-1)* HostEnum::PAGE_NUM;
        return DB::table($this->table)
            ->LeftJoin('product','product.product_id','=','collection.product_id')
            ->select('product.product_id','product.product_name','product.spec','product.place','product.stock','product.level','product.price','product.product_img')
            ->where('collection.user_id',$user_id)
            ->skip($offset)->take(HostEnum::PAGE_NUM)
            ->get();
    }

    /**
     * 判断是否收藏
     * @param $product_id
     * @return mixed
     * @author alice
     * @date 2016-1-26
     */
    public function GetCollectionById($product_id)
    {
        return  DB::table($this->table)
                ->where('product_id',$product_id)
                ->count();
    }

    /**
     * 验证是否收藏
     * @param $user_id
     * @param $product_id
     * @return mixed
     */
    public function CheckCollection($user_id, $product_id)
    {
        return  DB::table($this->table)
            ->where(['product_id' => $product_id, 'user_id' => $user_id])
            ->count();
    }




















}